﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using HZ.Supervise.Model.Enum;

namespace HZ.Supervise.Web.Secondphase
{
    public partial class SortSourceRateOfArea : BasePage
	{
        string sortSource = "''";

        public SortSourceRateOfArea()
        {
            this.ModuleNo = Module.趋势走向.ToString();
            this.PageOperateType = OperateType.县区采购类型所占比例.ToString();
        }
		protected void Page_Load(object sender, EventArgs e)
		{

			if (!IsPostBack)
			{

				areaID.InitAreaID = CurrentAccount.GetUser().Org.Area.AreaID;

				GvDataBind();

			}
		}
		/// <summary>
		/// 曹鹏
		/// 2011年5月20日11:01:06 
		/// 数据绑定
		/// </summary>
		private void GvDataBind()
		{
            //xg by张雄
            string timeFrom = string.Intern(this.txtTimeFrom.Text);

            string timeTo = string.Intern(this.txtTimeTo.Text);
            if (ddlSortSource.SelectedValue != "-1")
            {
                sortSource = this.ddlSortSource.SelectedValue;
            }
			string rate = this.txtRate.Text;

			string compare = this.ddlCompare.SelectedValue;

			string areaid = this.areaID.SelectedAreaID;

			string whereAreaId = "";

			string sort = ddlName.SelectedValue + "  " + ddlsort.SelectedValue;

			int total = 0;

			whereAreaId = Function.GetConditionOfAreaId(whereAreaId, areaid) as string;

			DataTable dt = HZ.Supervise.BLLFactory.ExecuteContext().ExecuteRateOfAreaSource(timeFrom,timeTo,sortSource, whereAreaId, compare, this.txtRate.Text, sort, AspNetPager1.PageSize, AspNetPager1.CurrentPageIndex, out total);

			AspNetPager1.RecordCount = total;

			Function.ChangeRate(dt, "DistributeRate", "addDistributeRate");

			Function.ChangeRate(dt, "WareHouseRate", "addWareHouseRate");

			Function.AddColumn(dt, "sortsource");

			Function.ChangeRate(dt, "sortsourcerate", "addsortsourcerate");

			this.gvwProcureCatalog.DataSource = dt;

			this.gvwProcureCatalog.DataBind();

			Function.Combine(gvwProcureCatalog);

		}

		protected void btnQuery_Click(object sender, EventArgs e)
		{

			AspNetPager1.CurrentPageIndex = 1;

		}

		protected void AspNetPager1_PageChanged(object sender, EventArgs e)
		{

			GvDataBind();

		}

		protected void btnExcel_Click(object sender, EventArgs e)
		{
            //xg by张雄
            string timeFrom = string.Intern(this.txtTimeFrom.Text);

            string timeTo = string.Intern(this.txtTimeTo.Text);

            if (ddlSortSource.SelectedValue != "-1")
            {
                sortSource = this.ddlSortSource.SelectedValue;
            }

			string rate = this.txtRate.Text;

			string compare = this.ddlCompare.SelectedValue;

			string areaid = this.areaID.SelectedAreaID;

			string whereAreaId = "";

			int total = 0;

			string sort = ddlName.SelectedValue + "   " + ddlsort.SelectedValue;

			whereAreaId = Function.GetConditionOfAreaId(whereAreaId, areaid) as string;

			DataTable dt = HZ.Supervise.BLLFactory.ExecuteContext().ExecuteRateOfAreaSource(timeFrom,timeTo,sortSource, whereAreaId, compare, this.txtRate.Text, sort,0, 1, out total);

			AspNetPager1.RecordCount = total;

			Function.ChangeRate(dt, "DistributeRate", "addDistributeRate");

			Function.ChangeRate(dt, "WareHouseRate", "addWareHouseRate");

			Function.AddColumn(dt, "sortsource");

			Function.ChangeRate(dt, "sortsourcerate", "addsortsourcerate");

			HZ.Excel.ExcelHelper.ExportDataForWeb(dt, this.gvwProcureCatalog);

		}
		protected void gvwProcureCatalog_RowDataBound(object sender, GridViewRowEventArgs e)
		{
			if (e.Row.RowType == DataControlRowType.DataRow)
			{
				e.Row.Cells[0].Text = HZ.Supervise.Web.Function.GetCityNameByCountryName(e.Row.Cells[0].Text);
			}
		}
	}
}
